import configure from '../../server/index.js'
import { showLoading,showErrMsg } from "../../../utils/msg.js"
import { userInfoKey } from "./../../../constant/index.js"

const serverLogin = (data) => {
	return new Promise((resolve,reject)=>{
		showLoading();
		//发起网络请求
		uni.request({
			url: `${configure.server.backServer}/xiaoshou/Login`,
			method: "GET",
			data,
			success: function (res) {
				uni.hideLoading();
				
				let data = res.data.data;
				
				if (res.data.code == 200) {
					//保存用户数据
					uni.setStorage({
					    key: userInfoKey,
					    data,
					    success: function () {
							uni.reLaunch({url:`/pages/index/index`})				
					    }
					});
					resolve(data);
				}else{
					showErrMsg(res.data.msg);
				}

			},
			fail:function(err){
				
				uni.hideLoading();
				showErrMsg('登录失败!');
			
			}
		});
	})
	
}

export { serverLogin }